package com.magicindicator.buildins;

import android.content.Context;
import android.util.DisplayMetrics;
import android.util.Log;

/**
 * 博客: http://hackware.lucode.net
 * Created by hackware on 2016/6/26.
 */
public final class UIUtil {

    private static final String TAG = "UIUtil";

    /**
     * 屏幕高度低于这个值，视为小屏幕
     */
    public static final int SMALL_SCREEN_HEIGHT_DP_BOUNDARY = 680;

    public static int dip2px(Context context, double dpValue) {
        float density = context.getResources().getDisplayMetrics().density;
        return (int) (dpValue * density + 0.5);
    }

    public static int getScreenWidth(Context context) {
        return context.getResources().getDisplayMetrics().widthPixels;
    }

    public static int getScreenHeight(Context context) {
        return context.getResources().getDisplayMetrics().heightPixels;
    }

    public static boolean isSmallScreen(Context context) {
        int screenHeightDp = getScreenHeightDp(context);
        Log.i(TAG, "isSmallScreen: screenHeightDp = " + screenHeightDp + " (SMALL_SCREEN_HEIGHT_DP_BOUNDARY = " + SMALL_SCREEN_HEIGHT_DP_BOUNDARY + ")");
        return screenHeightDp <= SMALL_SCREEN_HEIGHT_DP_BOUNDARY;
    }

    public static int getScreenWidthDp(Context context) {
        DisplayMetrics metric =  context.getResources().getDisplayMetrics();
        int width = metric.widthPixels;         // 屏幕宽度（像素）
        float density = metric.density;         // 屏幕密度（0.75 / 1.0 / 1.5）
        int screenWidthDp = (int) (width / density);  // 屏幕宽度(dp)
        return screenWidthDp;
    }

    public static int getScreenHeightDp(Context context) {
        DisplayMetrics metric =  context.getResources().getDisplayMetrics();
        int height = metric.heightPixels;       // 屏幕高度（像素）
        float density = metric.density;         // 屏幕密度（0.75 / 1.0 / 1.5）
        int screenHeightDp = (int) (height / density);// 屏幕高度(dp)
        return screenHeightDp;
    }
}